<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  
  
  <title>常用正则表达式 | 一枚前端小菜鸟的博客</title>
  <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
  <meta name="description" content="身份证号码 -&gt; 371428199911118888 &#x2F;^\d{6}(18|19|([23]\d))\d{2}((0[1-9])|(10|11|12))(([0-2][1-9])|10|20|30|31)\d{3}[0-9Xx]$&#x2F;  图片文件扩展名 -&gt; smile.jpg &#x2F;(jpg$)|(jpeg$)|(png$)|(bmp$)|(gif$)&#x2F;i  车牌号 -&gt; 苏A1">
<meta property="og:type" content="article">
<meta property="og:title" content="常用正则表达式">
<meta property="og:url" content="https://gitee.com/weiyayun1995/weiyayun1995.git/2021/04/13/%E5%B8%B8%E7%94%A8%E6%AD%A3%E5%88%99%E8%A1%A8%E8%BE%BE%E5%BC%8F/index.html">
<meta property="og:site_name" content="一枚前端小菜鸟的博客">
<meta property="og:description" content="身份证号码 -&gt; 371428199911118888 &#x2F;^\d{6}(18|19|([23]\d))\d{2}((0[1-9])|(10|11|12))(([0-2][1-9])|10|20|30|31)\d{3}[0-9Xx]$&#x2F;  图片文件扩展名 -&gt; smile.jpg &#x2F;(jpg$)|(jpeg$)|(png$)|(bmp$)|(gif$)&#x2F;i  车牌号 -&gt; 苏A1">
<meta property="og:locale" content="zh_CN">
<meta property="article:published_time" content="2021-04-13T02:39:30.000Z">
<meta property="article:modified_time" content="2021-04-22T09:52:27.717Z">
<meta property="article:author" content="yywei">
<meta property="article:tag" content="菜鸟,前端,js,react,vue">
<meta name="twitter:card" content="summary">
  
    <link rel="alternate" href="/atom.xml" title="一枚前端小菜鸟的博客" type="application/atom+xml">
  
  
    <link rel="shortcut icon" href="/favicon.png">
  
  
    
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/typeface-source-code-pro@0.0.71/index.min.css">

  
  
<link rel="stylesheet" href="/css/style.css">

  
    
<link rel="stylesheet" href="/fancybox/jquery.fancybox.min.css">

  
<meta name="generator" content="Hexo 5.4.0"></head>

<body>
  <div id="container">
    <div id="wrap">
      <header id="header">
  <div id="banner"></div>
  <div id="header-outer" class="outer">
    <div id="header-title" class="inner">
      <h1 id="logo-wrap">
        <a href="/" id="logo">一枚前端小菜鸟的博客</a>
      </h1>
      
        <h2 id="subtitle-wrap">
          <a href="/" id="subtitle">yywei的遇坑记录</a>
        </h2>
      
    </div>
    <div id="header-inner" class="inner">
      <nav id="main-nav">
        <a id="main-nav-toggle" class="nav-icon"></a>
        
          <a class="main-nav-link" href="/">Home</a>
        
          <a class="main-nav-link" href="/archives">Archives</a>
        
      </nav>
      <nav id="sub-nav">
        
          <a id="nav-rss-link" class="nav-icon" href="/atom.xml" title="RSS 订阅"></a>
        
        <a id="nav-search-btn" class="nav-icon" title="搜索"></a>
      </nav>
      <div id="search-form-wrap">
        <form action="//google.com/search" method="get" accept-charset="UTF-8" class="search-form"><input type="search" name="q" class="search-form-input" placeholder="搜索"><button type="submit" class="search-form-submit">&#xF002;</button><input type="hidden" name="sitesearch" value="https://gitee.com/weiyayun1995/weiyayun1995.git"></form>
      </div>
    </div>
  </div>
</header>

      <div class="outer">
        <section id="main"><article id="post-常用正则表达式" class="h-entry article article-type-post" itemprop="blogPost" itemscope itemtype="https://schema.org/BlogPosting">
  <div class="article-meta">
    <a href="/2021/04/13/%E5%B8%B8%E7%94%A8%E6%AD%A3%E5%88%99%E8%A1%A8%E8%BE%BE%E5%BC%8F/" class="article-date">
  <time class="dt-published" datetime="2021-04-13T02:39:30.000Z" itemprop="datePublished">2021-04-13</time>
</a>
    
  </div>
  <div class="article-inner">
    
    
      <header class="article-header">
        
  
    <h1 class="p-name article-title" itemprop="headline name">
      常用正则表达式
    </h1>
  

      </header>
    
    <div class="e-content article-entry" itemprop="articleBody">
      
        <ol>
<li><p>身份证号码 -&gt; 371428199911118888</p>
<p>/^\d{6}(18|19|([23]\d))\d{2}((0[1-9])|(10|11|12))(([0-2][1-9])|10|20|30|31)\d{3}[0-9Xx]$/</p>
</li>
<li><p>图片文件扩展名 -&gt; smile.jpg</p>
<p>/(jpg$)|(jpeg$)|(png$)|(bmp$)|(gif$)/i</p>
</li>
<li><p>车牌号 -&gt; 苏A123456</p>
<p>/^(京|津|沪|渝|冀|豫|云|辽|晋|湘|皖|鲁|鄂|苏|浙|赣|新|桂|甘|黑|蒙|陕|吉|闽|贵|粤|青|藏|川|宁|琼)[A-Za-z][A-Za-z0-9]{5,7}$/</p>
</li>
<li><p>手机号（宽松） -&gt; 19012345678</p>
<p>/^1[3-9]\d{9}$/</p>
</li>
<li><p>电子邮箱 -&gt; <a href="mailto:&#x6d;&#97;&#x69;&#108;&#64;&#x31;&#x36;&#x33;&#46;&#99;&#111;&#109;">&#x6d;&#97;&#x69;&#108;&#64;&#x31;&#x36;&#x33;&#46;&#99;&#111;&#109;</a></p>
<p>/^[a-zA-Z0-9.!#$%&amp;’<em>+/=?^_`{|}~-]+@<a href="?:%5Ba-zA-Z0-9-%5D%7B0,61%7D%5Ba-zA-Z0-9%5D">a-zA-Z0-9</a>?(?:.<a href="?:%5Ba-zA-Z0-9-%5D%7B0,61%7D%5Ba-zA-Z0-9%5D">a-zA-Z0-9</a>?)</em>$/</p>
</li>
<li><p>数字集合</p>
<p>/^([\d+,\d+])(;[\d+,\d+])*$/</p>
</li>
<li><p>护照 -&gt; E90000082</p>
<p>/(^[EeKkGgDdSsPpHh]\d{8}$)|(^(([Ee][a-fA-F])|([DdSsPp][Ee])|([Kk][Jj])|([Mm][Aa])|(1[45]))\d{7}$)/</p>
</li>
<li><p>匹配姓名拼音 ZHANG,SAN</p>
<p>/^[A-Z]+(,[A-Z]+)<em>(,·,[A-Z]+)</em>(,[A-Z]+)*$/</p>
</li>
<li><p>中国邮政编码 -&gt; 210000</p>
<p>/^(0[1-7]|1[0-356]|2[0-7]|3[0-6]|4[0-7]|5[1-7]|6[1-7]|7[0-5]|8[013-6])\d{4}$/</p>
</li>
<li><p>数字范围，逗号间隔(包含小数) -&gt; 11.11,22.2</p>
<p>/^(-?\d+(.\d{1,6}){0,1}),(-?\d+(.\d{1,6}){0,1})$/</p>
</li>
<li><p>手机号码(严谨)</p>
<p>/^1((3[\d])|(4[5,6,7,9])|(5[0-3,5-9])|(6[5-7])|(7[0-8])|(8[\d])|(9[1,8,9]))\d{8}$/</p>
</li>
<li><p>视频文件扩展名</p>
<p>/(mp4$)|(avi$)|(wmv$)|(rmvb$)/i</p>
</li>
<li><p>doc、ppt、xls 文件扩展名</p>
<p>/(doc$)|(docx$)|(ppt$)|(xls$)|(xlsx$)/i</p>
</li>
<li><p>金额正则表达式（限制最大值及小数点后位数）</p>
</li>
</ol>
<p>在element ui中checkNum()表示@input实时输入触发的函数</p>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line"><span class="function"><span class="title">checkNum</span>(<span class="params">val</span>)</span> &#123;</span><br><span class="line">    <span class="keyword">const</span> pattern = <span class="regexp">/^\d*(\.?\d&#123;0,2&#125;)/g</span></span><br><span class="line">    val = val.match(pattern)[<span class="number">0</span>] || <span class="string">&#x27;&#x27;</span></span><br><span class="line">    <span class="keyword">if</span> (<span class="built_in">Number</span>(val) &gt;= <span class="number">9999999.99</span>) &#123;</span><br><span class="line">        <span class="built_in">this</span>.money = <span class="number">9999999.99</span></span><br><span class="line">    &#125; <span class="keyword">else</span> &#123;</span><br><span class="line">        thismoney = val</span><br><span class="line">    &#125;</span><br><span class="line">&#125;,</span><br></pre></td></tr></table></figure>


      
    </div>
    <footer class="article-footer">
      <a data-url="https://gitee.com/weiyayun1995/weiyayun1995.git/2021/04/13/%E5%B8%B8%E7%94%A8%E6%AD%A3%E5%88%99%E8%A1%A8%E8%BE%BE%E5%BC%8F/" data-id="ckq7mlsvj000kdgt9gd362nev" data-title="常用正则表达式" class="article-share-link">分享</a>
      
      
      
    </footer>
  </div>
  
    
<nav id="article-nav">
  
    <a href="/2021/04/13/%E5%9C%A8for%E5%BE%AA%E7%8E%AF%E4%B8%AD%E8%B0%83%E7%94%A8%E5%BC%82%E6%AD%A5%E6%8E%A5%E5%8F%A3-%E6%89%A7%E8%A1%8C%E5%BC%82%E6%AD%A5%E4%BB%A3%E7%A0%81%E5%9D%97/" id="article-nav-newer" class="article-nav-link-wrap">
      <strong class="article-nav-caption">前一篇</strong>
      <div class="article-nav-title">
        
          在for循环中调用异步接口/执行异步代码块
        
      </div>
    </a>
  
  
    <a href="/2021/03/17/hexo%E6%90%AD%E5%BB%BA%E6%9C%AC%E5%9C%B0%E5%8D%9A%E5%AE%A2/" id="article-nav-older" class="article-nav-link-wrap">
      <strong class="article-nav-caption">后一篇</strong>
      <div class="article-nav-title">hexo搭建本地博客</div>
    </a>
  
</nav>

  
</article>


</section>
        
          <aside id="sidebar">
  
    

  
    

  
    
  
    
  <div class="widget-wrap">
    <h3 class="widget-title">归档</h3>
    <div class="widget">
      <ul class="archive-list"><li class="archive-list-item"><a class="archive-list-link" href="/archives/2021/06/">六月 2021</a></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2021/05/">五月 2021</a></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2021/04/">四月 2021</a></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2021/03/">三月 2021</a></li></ul>
    </div>
  </div>


  
    
  <div class="widget-wrap">
    <h3 class="widget-title">最新文章</h3>
    <div class="widget">
      <ul>
        
          <li>
            <a href="/2021/06/22/js%E6%95%B0%E6%8D%AE%E7%B1%BB%E5%9E%8B%E5%8F%8A%E8%BD%AC%E6%8D%A2/">js数据类型及转换</a>
          </li>
        
          <li>
            <a href="/2021/06/18/react-hook-%E9%A1%B9%E7%9B%AE%E4%B8%AD%E5%AE%9E%E8%B7%B5/">react-hook 项目中实践</a>
          </li>
        
          <li>
            <a href="/2021/06/18/%E6%95%B0%E5%AD%97%E7%AD%BE%E5%90%8D/">数字签名</a>
          </li>
        
          <li>
            <a href="/2021/06/18/sendbeacon/">sendbeacon</a>
          </li>
        
          <li>
            <a href="/2021/06/18/js%E6%95%B0%E6%8D%AE%E7%B1%BB%E5%9E%8B%E7%9A%84%E5%88%A4%E6%96%AD/">js数据类型的判断</a>
          </li>
        
      </ul>
    </div>
  </div>

  
</aside>
        
      </div>
      <footer id="footer">
  
  <div class="outer">
    <div id="footer-info" class="inner">
      
      &copy; 2021 yywei<br>
      Powered by <a href="https://hexo.io/" target="_blank">Hexo</a>
    </div>
  </div>
</footer>

    </div>
    <nav id="mobile-nav">
  
    <a href="/" class="mobile-nav-link">Home</a>
  
    <a href="/archives" class="mobile-nav-link">Archives</a>
  
</nav>
    


<script src="/js/jquery-3.4.1.min.js"></script>



  
<script src="/fancybox/jquery.fancybox.min.js"></script>




<script src="/js/script.js"></script>





  </div>
</body>
</html>